<template>
  <div>
    <van-datetime-picker
      v-model="currentDate"
      type="date"
      title="选择年月日"
      :min-date="minDate"
      :max-date="maxDate"
      @confirm="onConfirm"
      @cancel="onCancel"
    />
  </div>
</template>

<script>
import dayjs from 'dayjs'
import { name } from '@/api/info.js'
export default {
  name: 'birthday',
  props: ['birthday'],
  data () {
    return {
      minDate: new Date(1970, 0, 1),
      maxDate: new Date(),
      currentDate: new Date(this.birthday)
    }
  },
  methods: {
    async onConfirm () {
      this.$toast.loading({
        message: '加载中...',
        duration: 0, // 持续展示 toast
        forbidClick: true
      })
      try {
        await name({ birthday: dayjs(this.currentDate).format('YYYY-MM-DD') })
        this.$toast.success('修改成功')
        this.$emit('setData')
      } catch (error) {
        this.$toast.fail('修改失败')
      }
    },
    onCancel () {
      this.$emit('setShow')
    }
  }
}
</script>

<style>
</style>
